<template>
  <div class="app-container notify-css">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="全部" name="1"></el-tab-pane>
      <el-tab-pane label="未读" name="2"></el-tab-pane>
      <el-tab-pane label="已读" name="3"></el-tab-pane>
      <el-tab-pane label="待办" name="4"></el-tab-pane>
    </el-tabs>
    <template v-if="list.length>0">
      <el-scrollbar :style="customeStyle" class="my-common-scroll">
        <el-row class="msg-row" v-for="(item,index) in list" :key="index" @click.native="read(item)">
          <el-col class="msg-title" :span="1">
            {{item.content}}
          </el-col>
          <el-col class="msg-time" :span="1">
            {{item.time}}
          </el-col>
        </el-row>
      </el-scrollbar>
    </template>
    <el-empty v-else :description="msgDesc"></el-empty>
  </div>
</template>

<script>
  import {
    getNotifys,
    readNotify
  } from '@/api/system/queryData'
  export default {
    name: 'notify-home',
    data() {
      return {
        activeName: '1',
        list: [],
        customeStyle: {
          height: '300px',
        },
        msgDesc: '没有通知消息'
      }
    },
    created() {
      setTimeout(() => {
        this.getData()
      }, 2000)
    },
    methods: {
      handleClick() {
        this.getData()
      },
      getData() {
        this.list = []
        getNotifys({
          notifyType: this.activeName
        }).then(res => {
          if (res.status) {
            this.list = res.outputData.list
            if (this.list.length == 0) {
              if (this.activeName == 1) {
                this.msgDesc = '没有通知消息'
              } else if (this.activeName == 2) {
                this.msgDesc = '没有未读消息'
              } else if (this.activeName == '3') {
                this.msgDesc = '没有已读消息'
              } else if (this.activeName == 4) {
                this.msgDesc = '没有待办消息'
              }
            }
          }
        })
      },
      read(item) {
        if (item.read) {
          return
        }
        readNotify({
          id: item.id
        }).then(res => {
          if (res.status) {
            this.getData()
          }
        })
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .notify-css {
    .el-tabs {
      margin-bottom: 0px;
    }

    .msg-row {
      padding: 10px 0;
      border-bottom: solid 1px #f0f0f0;
      cursor: pointer;
    }

    .msg-title {
      font-size: 13px;
      width: calc(100% - 80px);
    }

    .msg-time {
      font-size: 13px;
      text-align: right;
      color: #1890ff;
      width: 80px;
      white-space: nowrap;
    }

    .el-tabs__nav-wrap::after {
      display: none;
    }
  }
</style>
